import type { DropdownItemOption } from 'vant';
import { SeriesItem } from './seriesModel';

// 游戏配置
export type GameConfig = {
  game_id: string;
  game_name: string;
  game_color: string;
  game_logo: string;
  open_series_search: 0 | 1; // 是否开启系列搜索，0-否、1-是
  is_show_ename: 0 | 1; // 是否展示其他名称
  is_show_card_no: 0 | 1; // 是否展示卡牌编号
  trade_game_id: string; // 商品游戏的ID
};

// 游戏搜索配置
export enum SearchLogicTypeEnum {
  OR = 'or',
  AND = 'and',
  NO = 'no',
}

export enum SearchStyleTypeEnum {
  DrawerLayer = 'drawer_layer',
  ShowLayer = 'show_layer',
  Text = 'text',
}

export enum SearchMapValTypeEnum {
  TEXT = 'text',
  IMAGE = 'image',
}

export type SearchMapItem = {
  key: string;
  value_type: SearchMapValTypeEnum;
  value: string;
};

export type SearchConfigItem = {
  title: string;
  attr_key: string;
  search_style: SearchStyleTypeEnum;
  search_logic: SearchLogicTypeEnum;
  mapping: SearchMapItem[];
};
// 实际使用的搜索条件的配置
export type SearchConfigDealItem = Writable<
  Omit<SearchConfigItem, 'mapping'> & {
    mapping: DropdownItemOption[];
  }
>;
export type SearchConfigList = SearchConfigItem[];

// 卡牌详情
export type CardFixedAttrItem = {
  id: number;
  card_no: string;
  name: string;
  ename: string;
  img: string;
  description: string;
  keywords: string[]; // 关键词
  price?: number;
  series_cn_abbr?: string; // 中文简称
  rarity?: string; // 稀有度
};

export type CardCustomAttrItem = {
  title: string;
  style: SearchMapValTypeEnum;
  imgs: string[];
  text: string;
};

export type CardFixedInfo = {
  card: CardFixedAttrItem;
  series: SeriesItem;
};

export type OtherVersionItem = {
  card_no: string;
  id: number;
  price: number;
  series_abbr: string;
  series_name: string;
  sindex: string;
};

export type CardInfoData = {
  card_fixed_attr: CardFixedInfo;
  card_custom_attrs: {
    up: CardCustomAttrItem[];
    down: CardCustomAttrItem[];
  };
  // 商城信息，没有该字段则表示该游戏下卡牌无商品信息。
  shopping: {
    min_price: number;
    link_url: string;
  };
  other_version: OtherVersionItem[];
  other_card_link_title: string; // 关联卡牌标题
  other_card_link_list: OtherVersionItem[];
};

export type CardItem = Pick<CardFixedAttrItem, 'id' | 'name' | 'img' | 'price' | 'series_cn_abbr'>;

export type CardList = {
  rows: CardItem[];
  total_page: number;
};

export type GameId = Pick<GameConfig, 'game_id'>;

// 卡牌查询参数
export type CardQueryParams = {
  game_id: string;
  page: number;
  size: number;
  name?: string;
  series_ids?: string[];
  [key: string]: any;
};

// 详情查询参数
export type CardDetailParams = Writable<GameId & Pick<CardFixedAttrItem, 'id'>>;

// 联想词
export type CardAssociativeWordParams = Writable<GameId & { search_key: string }>;
export type CardAssociativeWordData = { associative_words: string[] };

// 搜索记录
export type CardSearchHistoryData = {
  is_login: 0 | 1;
  history_words: string[];
};

export type CardSearchHistoryDelete = Writable<GameId & { delete_all?: 0 | 1; history_word?: string }>;
